package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCodingRule;
import com.ruoyi.system.service.ISysCodingRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 编码规则配置Controller
 * 
 * @author ruoyi
 * @date 2025-08-08
 */
@RestController
@RequestMapping("/system/rule")
public class SysCodingRuleController extends BaseController
{
    @Autowired
    private ISysCodingRuleService sysCodingRuleService;

    /**
     * 查询编码规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCodingRule sysCodingRule)
    {
        startPage();
        List<SysCodingRule> list = sysCodingRuleService.selectSysCodingRuleList(sysCodingRule);
        return getDataTable(list);
    }

    /**
     * 导出编码规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "编码规则配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCodingRule sysCodingRule)
    {
        List<SysCodingRule> list = sysCodingRuleService.selectSysCodingRuleList(sysCodingRule);
        ExcelUtil<SysCodingRule> util = new ExcelUtil<SysCodingRule>(SysCodingRule.class);
        util.exportExcel(response, list, "编码规则配置数据");
    }

    /**
     * 获取编码规则配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(sysCodingRuleService.selectSysCodingRuleByRuleId(ruleId));
    }

    /**
     * 新增编码规则配置
     */
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "编码规则配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCodingRule sysCodingRule)
    {
        return toAjax(sysCodingRuleService.insertSysCodingRule(sysCodingRule));
    }

    /**
     * 修改编码规则配置
     */
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "编码规则配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCodingRule sysCodingRule)
    {
        return toAjax(sysCodingRuleService.updateSysCodingRule(sysCodingRule));
    }

    /**
     * 删除编码规则配置
     */
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "编码规则配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(sysCodingRuleService.deleteSysCodingRuleByRuleIds(ruleIds));
    }
}
